<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<%response.setHeader("Pragma","No-cache");
	response.setHeader("Cache-Control","no-cache");
	response.setDateHeader("Expires", 0);
	response.flushBuffer();%>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title>ECharts</title>
</head>
<body>
<!-- 为ECharts准备一个具备大小（宽高）的Dom -->
<div id="main" style="height:550px"></div>
<!-- ECharts单文件引入 -->
<script type="text/javascript" src="${ctxStatic}/ajz/js/jquery.min.js"></script>
<script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        search();
    });
    function search() {
        var msg = 'species';
        var enterpriseType = $("#enterpriseType").val();
        $.ajax({
            url: "/a/ajz/ajzBaseinfo/findArea",
            type: "POST",
            data: "msg="+msg+"&enterpriseType="+enterpriseType,
            dataType: "json",
            async: true,
            success: function (map) {
                var firstGrip = parseInt(map.firstGrip);
                var secordGrip = parseInt(map.secordGrip);
                var thirdGrip = parseInt(map.thirdGrip);
                var otherGrip = parseInt(map.otherGrip);
                getDate(firstGrip,secordGrip,thirdGrip,otherGrip);
            }
        });
    };

function getDate(firstGrip,secordGrip,thirdGrip,otherGrip) {
    // 路径配置
    require.config({
        paths: {
            echarts: 'http://echarts.baidu.com/build/dist'
        }
    });
    // 使用
    require(
        [
            'echarts',
            'echarts/chart/pie' // 使用柱状图就加载bar模块，按需加载
        ],
        function (ec) {
            // 基于准备好的dom，初始化echarts图表
            var myChart = ec.init(document.getElementById('main'));

            option = {
                title: {
                    text: '企业网格分布',
                    x: 'right',
                    y: 'bottom'
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    x: 'left',
                    data: ['第一网格', '第二网格', '第三网格', '其他网格']
                },
                toolbox: {
                    show: true,
                    feature: {
                        mark: {show: true},
                        dataView: {show: true, readOnly: false},
                        restore: {show: true},
                        saveAsImage: {show: true}
                    }
                },
                calculable: false,
                series: (function () {
                    var series = [];
                    for (var i = 0; i < 30; i++) {
                        series.push({
                            name: '企业数量（安全生产）',
                            type: 'pie',
                            itemStyle: {
                                normal: {
                                    label: {show: i > 28},
                                    labelLine: {show: i > 28, length: 20}
                                }
                            },
                            radius: [i * 4 + 40, i * 4 + 43],
                            data: [
                                {value: firstGrip, name: '第一网格'},
                                {value: secordGrip, name: '第二网格'},
                                {value: thirdGrip, name: '第三网格'},
                                {value: otherGrip, name: '其他网格'}
                            ]
                        })
                    }
                    series[0].markPoint = {
                        symbol: 'emptyCircle',
                        symbolSize: series[0].radius[0],
                        effect: {
                            show: true,
                            scaleSize: 12,
                            color: 'rgba(250,225,50,0.8)',
                            shadowBlur: 10,
                            period: 30
                        },
                        data: [{x: '50%', y: '50%'}]
                    };
                    return series;
                })()
            };
            setTimeout(function () {
                var _ZR = myChart.getZrender();
                var TextShape = require('zrender/shape/Text');
                // 补充千层饼
                _ZR.addShape(new TextShape({
                    style: {
                        x: _ZR.getWidth() / 2,
                        y: _ZR.getHeight() / 2,
                        color: '#666',
                        text: '企业分布',
                        textAlign: 'center'
                    }
                }));
                _ZR.addShape(new TextShape({
                    style: {
                        x: _ZR.getWidth() / 2 + 200,
                        y: _ZR.getHeight() / 2,
                        brushType: 'fill',
                        color: 'orange',
                        text: '',
                        textAlign: 'left',
                        textFont: 'normal 20px 微软雅黑'
                    }
                }));
                _ZR.refresh();
            }, 2000);

            // 为echarts对象加载数据
            myChart.setOption(option);
        }
    );
}
</script>
</body>